import request from '@/utils/request'
import { User } from '@/model/user'
import { PageDate, PageQuery } from '@/model/index'
/**
 * 获取图形验证码
 * @param data
 * @returns
 */
export function fetchLoginImg() {
  return request.get('/api/auth/login/img')
}

/**
 * 登录
 * @param data
 * @returns
 */
export function fetchLogin(data: any) {
  return request.post('/api/auth/login/', data)
}

/**
 * 刷新token
 * @param data
 * @returns
 */
export function refreshToken(data: any) {
  return request.get('/api/auth/login/refreshToken', data)
}

/**
 * 获取用户信息
 * @returns  {activeUsers, storeInfo, menu, permissions}
 */
export const fetchUserInfo = () => request.get('/api/auth/login/me')

/**
 * 获取用户列表
 * @returns
 */
export function fetchUserPage(params: PageQuery<User>): Promise<PageDate<User>> {
  return request.get<PageDate<User>>('/api/auth/user/page', params)
}

/**
 * 添加用户
 * @param data
 * @returns
 */
export function addUser(data: User): Promise<null> {
  return request.post<null>('/api/auth/user/', data)
}

/**
 * 修改用户
 * @param data
 * @returns
 */
export function updateUser(id: string, data: User): Promise<null> {
  return request.put<null>(`/api/auth/user/${id}`, data)
}

/**
 * 删除用户
 * @param id
 */
export function delUser(id: string): Promise<null> {
  return request.delete<null>(`/api/auth/user/${id}`)
}
